本例子可以用来简化在 C# 应用中异步的访问 Web 服务的操作。同时包含文件上传和访问网页的方法。
Get data from web service
Request.Get("http://jthorne.co.uk/", result=>{ Console.Write(result);});
Download file from server
Request.Get("http://cachefly.cachefly.net/100mb.test", (headers, result) =>{ FileStream fs = new FileStream(@"C:\100mb.test", FileMode.OpenOrCreate); result.CopyTo(fs); fs.Close();});
Post data to web service
Request.Post("http://testing.local/post.php", new {name="james",username="Redslide"}, result=>{ Console.Write(result);});
Post data to web service and catch error
Request.Post("http://testing.local/post.php", new { name = "value"}, result=>{ Console.Write(result);}, e=>{ Console.Write(e.ToString());});
Upload file to server
Request.Upload("upload/attach/202206/img/605_44630.jpg", "image/jpeg", new FileStream(@"C:\photo.jpg",FileMode.Open))}, result=>{ Console.Write(result);});
评论